<template>

	<ListLayout>
		<AttachmentCard ref="AttachmentCard"></AttachmentCard>
		<EvaluationCard ref="EvaluationCard"></EvaluationCard>
		<SignCard ref="SignCard"></SignCard>

		<template #footer>
			<HButtonGroup @leftClick="onCancel" @rightClick="onSubmit">
				<template #left>
					取消
				</template>
				<template #right>
					确认
				</template>
			</HButtonGroup>
		</template>
	</ListLayout>
</template>

<script>
	import ListLayout from '@/components/layout/listLayout.vue'

	import AttachmentCard from '@/components/card/attachment.vue'
	import EvaluationCard from '@/components/card/evaluation.vue'
	import SignCard from '@/components/card/sign.vue'
	import HButtonGroup from '@/components/buttonGroup/groupTwo.vue'
	import { attachmentFormatter } from '@/common/submitFormatter.js'
	import { mathSum } from '@/filter/index.js'
	import { submitEvalutaion } from '@/apis/evaluation.js'
	export default {
		components: {
			ListLayout,
			AttachmentCard,
			EvaluationCard,
			SignCard,
			HButtonGroup
		},
		data() {
			return {
				routerParams: {
					orderNum: '',
				}

			}
		},
		onLoad(params) {
			this.initParams(params)

		},
		onUnload() {},
		methods: {
			//初始化路由携带过来的参数
			initParams(queryParams) {
				let { orderNum, reporter } = queryParams
				this.$set(this.routerParams, 'orderNum', orderNum || '')

			},

			// 取消评价
			onCancel() {
				wx.redirectTo({
					url: '/pages/myOrder/order'
				})
			},
			// 确认评价 
			onSubmit() {
				let { AttachmentCard, EvaluationCard, SignCard } = this.$refs
				let { attachment } = AttachmentCard.$data
				let { evaluationData } = EvaluationCard.$data
				let { manner, quality, responseTimeliness, text } = evaluationData

				SignCard.upSign(async (file) => {
					const params = {
						/** 工单号 */
						orderNum: this.routerParams.orderNum,
						/** 附件 */
						enclosure: attachmentFormatter(attachment),
						/** 服务态度 */
						serviceAttitude: manner,
						/** 服务质量 */
						serviceQuality: quality,
						/** 响应时效 */
						responsePrescription: responseTimeliness,
						/** 意见与建议 */
						commentSuggestion: text,
						/** 签名 */
						autograph: file?.url || '',
						/** 评价结果 */
						evaluateResult: mathSum([manner, quality, responseTimeliness]),
						/** 类型（1.完成评价 ，后续有其他再加） */
						type: '1'
					}
					await submitEvalutaion(params)
					wx.showToast({
						title: '评价成功!',
						icon: 'success',
						mask: true,
						complete() {
							wx.redirectTo({
								url: '/pages/myOrder/order'
							})
						}
					})
				})







			}
		},
	}
</script>
